@include('admin.public.head')

<div class="ibox-title">
    <h5>等级添加</h5><br/><br/>
    <h5>
    @foreach($headhunting_commission_level as $v)
        {{$v->rank_name}}：{{$v->rank_min}}&nbsp;&nbsp;
    @endforeach
    </h5>
</div>

<div class="ibox-content">
    <form  class="form-horizontal">
        <div class="form-group">
            <label class="col-sm-3 control-label">等级名称：</label>
            <div class="col-sm-9">
                <input type="text" name="rank_name" class="form-control"  value="{{$result->rank_name??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">该等级经验值下限：</label>
            <div class="col-sm-9">
                <input type="text" name="rank_min" class="form-control"  value="{{$result->rank_min??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">等级折扣(购买课程)：</label>
            <div class="col-sm-9">
                <input type="text" name="buy_discount" class="form-control"  value="{{$result->buy_discount??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">级别：</label>
            <div class="col-sm-9">
                <input type="text" name="level" class="form-control"  value="{{$result->level??''}}">
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <div class="form-group">
            <label class="col-sm-3 control-label">简述：</label>
            <div class="col-sm-9">
                <textarea type="text" name="sketch" class="form-control"  value="{{$result->sketch??''}}"></textarea>
            </div>
        </div>
        <div class="hr-line-dashed"></div>

        <input type="hidden" name="id" value="{{$id??0}}">

        <div class="form-group">
            <div class="col-sm-4 col-sm-offset-3">
                <button class="btn btn-primary do" type="submit">操作</button>
                <a class="btn btn-primary"  href="/level">等级管理</a>
            </div>
        </div>
    </form>
</div>

<script>
    $('.do').click(function(){
        var form = new FormData();

        var rank_name = $('input[name="rank_name"]').val();
        var rank_min = $('input[name="rank_min"]').val();
        var buy_discount = $('input[name="buy_discount"]').val();
        var sketch = $('textarea[name="sketch"]').val();
        var level = $('input[name="level"]').val();
        var id = $('input[name="id"]').val();

        form.append("rank_name", rank_name);
        form.append("rank_min", rank_min);
        form.append("buy_discount", buy_discount);
        form.append("level", level);
        form.append("id", id);
        form.append("sketch", sketch);

        $.ajax({
            type: 'POST',
            url: '/level_do' ,
            dataType:"json",   //返回格式为json
            data: form ,
            processData: false,
            contentType: false,
            success:function(data){

                if(data.status == '1') {
                    var swal_json = {
                        title: data.message,
                        type: "success"
                    }

                    swal(swal_json, function (isConfirm) {
                        window.location.reload();
                    });

                }else{
                    var swal_json = {
                        title: data.message,
                        type: "error"
                    }

                    swal(swal_json, function (isConfirm) {

                    });
                }
            }
        });

        return false;
    });
</script>
